
package com.vishnu.main;

import java.util.HashSet;
import java.util.Set;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import com.vishnu.pojo.Address;
import com.vishnu.pojo.Employee;

public class Delete {

	public static void main(String[] args) {
		Configuration cfg =new Configuration();
		cfg.configure("hib.cfg.xml");
		SessionFactory sf=cfg.buildSessionFactory();
		Session hsession=sf.openSession();
		Transaction tx=hsession.beginTransaction();
	System.out.println("---------transaction started--------");
	Employee employee=new Employee();
	employee.setEmployeeId(2);
	employee.setEmployeeName("prudvi");
	employee.setEmployeeSalary(7543.);
	

	
	Address address=new Address();
	address.setAid(3);
	address.setEmployee(employee);
	address.setStreetName("kodur");
	address.setState("AP");
	address.setCountry("INDIA");
	
	Address address2=new Address();
	address2.setAid(4);
	address2.setEmployee(employee);
	address2.setStreetName("Palm court");
	address2.setState("KL");
	address2.setCountry("Malaysia");
	
	Set addrss=new HashSet();
	addrss.add(address);
	addrss.add(address2);
	employee.setAddresses(addrss);
	
	
	hsession.save(employee);
	
/*	Employee employee=new Employee();
	employee.setEmployeeId(1);
	hsession.delete(employee);*/
	
		tx.commit();
		hsession.close();
		sf.close();
	}	
}
